<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" media="screen" href="/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/css/treetable/jquery.treetable.css"/>
    <link rel="stylesheet" href="/css/treetable/jquery.treetable.theme.default.css"/>
    <link rel="stylesheet" type="text/css" href="/css/bootstrap-select.min.css">
    <link rel="stylesheet" type="text/css" href="/at-js/css/jquery.atwho.css">
    <script src="/js/libs/jquery-2.1.1.min.js"></script>
    <script src="/js/bootstrap/bootstrap.min.js"></script>
    <script src="/js/bootstrap/bootstrap-select.min.js"></script>
    <script src="/js/jq.js"></script>
    <script src="/js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
    <script src="/js/common.js"></script>
    <script src="/layui/layui.js"></script>
    <script src="/js/dict.js"></script>
    <script src="/js/libs/jquery.ztree.all-3.5.min.js"></script>
    <script src="/js/my/ztree-menu.js"></script>
    <script src="/js/my/permission.js"></script>
    <script src="/js/plugin/datatables/jquery.dataTables.min.js"></script>
    <script src="/js/plugin/datatables/dataTables.bootstrap.min.js"></script>
    <script src="/js/libs/jquery.treetable.js"></script>
    <script src="/js/plugin/jquery-caret/jquery.caret.js"></script>
    <script src="/at-js/js/jquery.atwho.js"></script>
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-md-offset-2 col-lg-offset-2">
    <form class="form-horizontal" onsubmit="return false" id="form">
        <fieldset>
            <div class='form-group'>
                <label class='col-md-4 control-label'>调配来货人</label>
                <div class='col-md-8'>
                    <input class='form-control' type='hidden' name='handlerId' id='handlerId'>
                    <input style="width: 90%;float: left;" class='form-control' placeholder='调配来货人' type='text'
                           name='handlerName' id='handlerName'
                           readonly>
                    <button style="width: 10%;float: right; height: 32px; line-height: 32px;"
                            class="layui-btn layui-btn-sm"
                            onclick="showTableAndFlushFields('user', 'user', '用户', true, false, 'handlerId:id', 'handlerName:nickname', 'deployComeId:deptId', 'deployComeName:deptName')">
                        <i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </div>

            <div class='form-group'>
                <label class='col-md-4 control-label'>调配来货部门</label>
                <div class='col-md-8'>
                    <input class='form-control' type='hidden' name='deployComeId' id='deployComeId'>
                    <input style="width: 90%;float: left;" class='form-control' placeholder='调配来货部门' type='text'
                           name='deployComeName' id='deployComeName' readonly>
                    <button style="width: 10%;float: right; height: 32px; line-height: 32px;"
                            class="layui-btn layui-btn-sm"
                            onclick="showSpecialTree('deployComeId', 'deployComeName', 'dept', '部门', 'root', 'select','fasDeptTree', true, true)">
                        <i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </div>
            <div class='form-group'>
                <label class='col-md-4 control-label'>调配配送人员</label>
                <div class='col-md-8'>
                    <input class='form-control' type='hidden' name='deployForpeoId' id='deployForpeoId'>
                    <input style="width: 90%;float: left;" class='form-control' placeholder='调配配送人员' type='text'
                           name='deployForpeoName' id='deployForpeoName'
                           readonly>
                    <button style="width: 10%;float: right; height: 32px; line-height: 32px;"
                            class="layui-btn layui-btn-sm"
                            onclick="showTableAndFlushFields('user', 'user', '用户', true, false, 'deployForpeoId:id', 'deployForpeoName:nickname', 'deployForId:deptId', 'deployForName:deptName')">
                        <i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </div>
            <div class='form-group'>
                <label class='col-md-4 control-label'>调配配送部门</label>
                <div class='col-md-8'>
                    <input class='form-control' type='hidden' name='deployForId' id='deployForId'>
                    <input style="width: 90%;float: left;" class='form-control' placeholder='调配配送部门' type='text'
                           name='deployForName' id='deployForName' readonly>
                    <button style="width: 10%;float: right; height: 32px; line-height: 32px;"
                            class="layui-btn layui-btn-sm"
                            onclick="showSpecialTree('deployForId', 'deployForName', 'dept', '部门', 'root', 'select','fasDeptTree', true, true)">
                        <i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </div>
            <div class='form-group'>
                <label class='col-md-4 control-label'>商品</label>
                <div class='col-md-8'>
                    <input class='form-control' type='hidden' name='goodsId' id='goodsId'>
                    <input style="width: 90%;float: left;" class='form-control' placeholder='商品' type='text'
                           name='goodsName' id='goodsName' readonly>
                    <button style="width: 10%;float: right; height: 32px; line-height: 32px;"
                            class="layui-btn layui-btn-sm"
                            onclick="showTableAndFlushFields('fas/goods','goods', '商品', true, false, 'goodsId:id', 'goodsName:name', 'detailSpec:specification', 'detailUnit:unit')">
                        <i class="layui-icon">&#xe615;</i>
                    </button>
                </div>
            </div>
            <div class='form-group'>
                <label class='col-md-4 control-label'>明细规格</label>
                <div class='col-md-8'>
                    <input class='form-control' placeholder='明细规格' readonly type='text' name='detailSpec'
                           id='detailSpec'>
                </div>
            </div>
            <div class='form-group'>
                <label class='col-md-4 control-label'>明细单位</label>
                <div class='col-md-8'>
                    <input class='form-control' placeholder='明细单位' readonly type='text' name='detailUnit'
                           id='detailUnit'>
                </div>
            </div>
            <div class='form-group'>
                <label class='col-md-4 control-label'>明细数量</label>
                <div class='col-md-8'>
                    <input class='form-control' placeholder='明细数量' type='text' name='detailNum' id='detailNum'
                           data-bv-notempty='true' data-bv-notempty-message='明细数量 不能为空'>
                </div>
            </div>
            <div class='form-group'>
                <label class='col-md-4 control-label'>备注</label>
                <div class='col-md-8'>
                    <textarea class="form-control" placeholder="备注" name="remark" id="remark"></textarea>
                </div>
            </div>
            <div class="form-actions">
                <div class="row" align="center">
                    <div class="col-md-12">
                        <button class="btn btn-primary" onclick="location.href='handOverList.html'">返回</button>
                        <button class="btn btn-primary" type="submit" onclick="save()">
                            <i class="fa fa-save"></i> 保存
                        </button>
                    </div>
                </div>
            </div>
        </fieldset>
    </form>
</div>
<script type="text/javascript">
    $(function () {
        $('#form').bootstrapValidator();
        runAt('remark');
    });

    function runAt(elementId) {
        var users = [];

        $.ajax({
            type: 'get',
            url: '/users/listAll',
            async: false,
            success: function (json) {
                if (json.code === 0) {
                    users = json.data;
                }
            }
        });

        var at_config = {
            at: "@",
            data: users,
            searchKey: 'nickname',
            headerTpl: '<div class="atwho-header">User List<small>↑&nbsp;↓&nbsp;</small></div>',
            insertTpl: '@${nickname}',
            displayTpl: "<li>${nickname} <small>${username}</small></li>",
            limit: 200
        };

        var $inputor = $('#' + elementId).atwho(at_config);
        $inputor.caret('pos', 47);
        $inputor.focus().atwho('run');
    }

    layui.use('layer', function () {
        var layer = layui.layer;
    });

    function save() {
        $('#form').bootstrapValidator();
        var bootstrapValidator = $("#form").data('bootstrapValidator');
        bootstrapValidator.validate();
        if (!bootstrapValidator.isValid()) {
            return;
        }

        var formdata = $("#form").serializeObject();

        $.ajax({
            type: 'post',
            url: '/handOver/',
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(formdata),
            success: function (data) {
                if (data.code == 0) {
                    layer.msg("添加成功", {shift: -1, time: 1000}, function () {
                        // location.href = "handOverList.html";
                        deleteCurrentTab();
                        $('#menu a[data-url="pages/fas/handOver/handOverList.html"]').click();
                    });
                } else {
                    layer.msg(data.message);
                }
            }
        });
    }


</script>
</body>
</html>
